#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2018 crane <crane@his-pc>
#
# Distributed under terms of the MIT license.

"""

"""

from hash_heap import *


class LRUValue(HeapValue):
    def __init__(self, key, value=None, access_cnt=0, access_stamp=0):
        # TODO
        super(key, value)
        # self.key = key              # 反向索引到hash中
        # self.value = value

        self.access_cnt = access_cnt
        self.access_stamp = access_stamp


    # TODO 添加比较函数
    def __cmp__(self, other):
        pass


class LRUCache:
    def __init__(self, capacity):
        self.heap_hash = HashHeap
        self.capacity = capacity
        self.available = capacity

    def set(self, key, value):
        if key in self.hash:
            lru_value = self.heap_hash.get(key)
            lru_value.value = value
            self.heap_hash.update(key, lru_value)
            # self.hash[key].value = value        # 处理cnt
            # self.hash[key].adjust()             # TODO
        else:
            cache_value = LRUValue(value)       # TODO init处理cnt
            node = TreeNode(cache_value)
            # self.hash[key] = node

            if self.available:
                self.
            else:
                self.heap.push(key)
                self.heap.pop()
        # if not self.available:
        #     pop_key = self.stack.pop()
        #     del self.hash[pop_key]

        # self.stack.append(key)

        self.hash[key] = value

    @property
    def available(self):
        return self.capacity - len(self.stack)

    def get(self, key):
        return self.hash.get(key, -1)

    def show(self):
        print('=================== hash  [%s] =====================' % self.hash)
        print('=================== stack [%s] =====================' % self.stack)


def main():
    print("start main")

if __name__ == "__main__":
    main()
